package com.heima.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.dtos.AuthDto;
import com.heima.model.user.pojos.ApUserRealname;
import com.heima.user.mapper.ApUserRealnameMapper;
import com.heima.user.service.ApUserRealnameService;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

@Service
public class ApUserRealnameServiceimpl extends ServiceImpl<ApUserRealnameMapper, ApUserRealname> implements ApUserRealnameService {
    @Override
    /**
     * 认证数据分页查询
     * @param authDto
     * @return
     */
    public PageResponseResult pageList(AuthDto authDto) {
        Page IPage=new Page(authDto.getPage(),authDto.getSize());
        LambdaQueryWrapper<ApUserRealname> mapper=new LambdaQueryWrapper<>();
        if (authDto.getStatus()!=null) {
            mapper.eq(ApUserRealname::getStatus, authDto.getStatus());
        }
        mapper.orderByAsc(ApUserRealname::getCreatedTime);
        Page page = page(IPage, mapper);
        PageResponseResult pageResponseResult = new PageResponseResult(authDto.getPage(), authDto.getSize(), (int) page.getTotal());
        pageResponseResult.setData(page.getRecords());
        return pageResponseResult;
    }
    /**
     * 审核失败
     * @param authDto
     * @return
     */
    @Override
    public ResponseResult authFail(AuthDto authDto) {
        ApUserRealname apUserRealname = new ApUserRealname();
        apUserRealname.setId(authDto.getId());
        apUserRealname.setReason(authDto.getMsg());
        apUserRealname.setStatus((short)2);
        updateById(apUserRealname);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
    /**
     * 审核成功
     * @param authDto
     * @return
     */
    @Override
    public ResponseResult authPass(AuthDto authDto) {
        ApUserRealname apUserRealname = new ApUserRealname();
//        apUserRealname.setReason(authDto.getMsg());
        apUserRealname.setId(authDto.getId());
        apUserRealname.setStatus((short)9);
        updateById(apUserRealname);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }


}
